// FlowerController.java
package com.sun.huazhi.aitaskservice.controller;

import com.sun.huazhi.aitaskservice.DTO.request.FlowerQARequest;
import com.sun.huazhi.aitaskservice.DTO.response.FlowerQAResponse;
import com.sun.huazhi.aitaskservice.common.config.PythonApiProperties;
import com.sun.huazhi.aitaskservice.common.resilience.ResilientServiceExecutor;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

@RestController
@RequestMapping("/api/flower")
@Tag(name = "插花艺术智能问答", description = "提供插花艺术相关的自然语言问答功能")
public class FlowerController {

    @Autowired
    @Qualifier("pythonApiProperties")
    private PythonApiProperties apiProps;

    @Autowired
    private WebClient webClient;

    @Autowired
    private ResilientServiceExecutor resilientExecutor;

    @PostMapping("/query")
    @Operation(summary = "插花艺术问答",
            description = "发送关于插花艺术的自然语言查询，获取专业建议，可选择生成相关图像")
    public Mono<ResponseEntity<FlowerQAResponse>> flowerQA(@RequestBody FlowerQARequest request) {
        return resilientExecutor.execute(() ->
                webClient.post()
                        .uri(apiProps.getUrl() + "/query")
                        .contentType(MediaType.APPLICATION_JSON)
                        .bodyValue(request)
                        .retrieve()
                        .bodyToMono(FlowerQAResponse.class)
                        .map(ResponseEntity::ok)
        );
    }
}